<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>用户登录</title>
<!--CSS-->
<link rel="stylesheet" type="text/css"
	href="static/js/third-js/extjs66/theme-neptune/resources/theme-neptune-all.css" />
<!--js-->
<script type="text/javascript" src="static/js/third-js/extjs66/ext-all.js"></script>
<script type="text/javascript" src="static/js/public/variable.js"></script>
<script type="text/javascript">
	Ext.onReady(function() {
		var loginForm = Ext.create("Ext.form.Panel", {
			standardSubmit : true,
			title : '用户登陆',
			width : 320,
			bodyPadding : 10,
			defaultType : 'textfield',
			referenceHolder: true,
			defaultButton: 'loginButton',
			defaults : {
				anchor : '100%',
				labelWidth : 50,
				labelAlign : "right"
			},
			items : [ {
				allowBlank : false,
				fieldLabel : '用户名',
				name : 'username',
				emptyText : '用户名'
			}, {
				allowBlank : false,
				fieldLabel : '密码',
				name : 'password',
				emptyText : '密码',
				inputType : 'password'
			}, {
				xtype : 'checkbox',
				fieldLabel : '记住我',
				name : 'remember'
			} ],
			buttons : [
			// 		{
			// 	text : '新用户注册',
			// 	handler : function() {
			// 		document.location.href='/'+webServiceName+'/register';
			// 	}
			// },
				{
				text : '登陆',
				reference: 'loginButton',
				handler : function() {
					if (!loginForm.getForm().isValid())
						return;
					Ext.Ajax.request({
					     url: '/'+authServiceName+'/login',
					     method:'post',
					     params:{
					    	 userName:loginForm.getForm().findField('username').lastValue,
					    	 password:loginForm.getForm().findField('password').lastValue
					     },
					     success: function(response, opts) {
					     	var result=Ext.JSON.decode(response.responseText);
					     	if(result.code==401)
								Ext.Msg.alert('错误', '用户名不存在！');
					     	else if(result.code==400)
								Ext.Msg.alert('错误', '密码错误！');
					     	else
								document.location.href='/training-web-service/training';
					     },
					     failure: function(response, opts) {
					         console.log('server-side failure with status code ' + response.status);
					     }
					 });
				}
			} ]
		});
		Ext.create('Ext.window.Window', {
		   header:false,
		   layout: 'fit',
		   items: [loginForm]
		}).show();
	});
</script>
</head>
<body>
</body>
</html>